﻿using dotnet2cache.Abstractions;
using dotnet2cache.Core;
using System;
using System.Collections.Generic;
using System.Text;

namespace dotnet2cache.CsRedis
{
    class Level2CacheProvider : ILevel2CacheProvider
    {
        public CacheValue<T> Get<T>(string key)
        {
          var value= L2CacheRedisHelper.Get<T>(key);
           
            return new CacheValue<T>(value);
        }

        public bool IsExist(string key)
        {
            return L2CacheRedisHelper.Exists(key);
        }

        public bool Remove(string key)
        {
            L2CacheRedisHelper.Del(key);
            return true;
        }

        public void Set<T>(string key, CacheValue<T> value, CacheOptionEntry cacheOptionEntry)
        {
            if(cacheOptionEntry.Level2Expiration.HasValue)
            {
                L2CacheRedisHelper.Set(key, value.Value, cacheOptionEntry.Level2Expiration.Value.Second);
                return;
            }
            L2CacheRedisHelper.Set(key, value.Value);
        }
    }
}
